package com.geekstudy.week2;

import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
import org.apache.hc.client5.http.async.methods.SimpleHttpRequests;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.Method;
import org.apache.hc.core5.http.io.entity.EntityUtils;

import java.util.Map;

/**
 *
 * http://hc.apache.org/httpcomponents-client-5.1.x/quickstart.html
 * https://mvnrepository.com/artifact/org.apache.httpcomponents.client5/httpclient5
 *
 * https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient/4.5.13
 *
 */
public class HttpClientTool {


    public String get(String url) {
        String response = null;
        try {
            CloseableHttpClient httpClient = HttpClients.createDefault();
            HttpGet httpGet = new HttpGet(url);
            CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
            response = EntityUtils.toString(httpEntity);


        } catch(Exception e) {
            System.out.println("HttpClientTool exception");
            e.printStackTrace();
        }
        return response;
    }
}
